package com.nami.message.acl.repository.sendbox;

import com.nami.message.domain.model.pmsg.PChatMsgModel;
import com.nami.message.domain.model.gmsg.GrpMsgDomain;
import com.nami.message.domain.repository.SendBoxRepository;
import com.nami.message.acl.repository.sendbox.convertor.Model2SendBoxDOConvertor;
import com.nami.message.core.mybatis.dataobject.SendboxMsgsDO;
import com.nami.message.core.mybatis.mapper.SendboxMsgsMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RequiredArgsConstructor
public class SendBoxRepositoryImpl implements SendBoxRepository {

    private final SendboxMsgsMapper sendboxMsgsMapper;

    @Override
    public boolean add(PChatMsgModel msgModel) {
        SendboxMsgsDO sendboxMsgsDO = Model2SendBoxDOConvertor.toDO(msgModel);
//        SendboxMsgsDO sendboxMsgsDO = SendBoxConvert.INSTANCE.convert(msgModel);
        int result = sendboxMsgsMapper.insert(sendboxMsgsDO);
        if (result < 1) {
            return Boolean.FALSE;
        }
        return Boolean.TRUE;
    }

    @Override
    public boolean addGrpMsg(GrpMsgDomain grpMsgDomain) {
        SendboxMsgsDO sendboxMsgs = new SendboxMsgsDO();
        sendboxMsgs.setUserId(grpMsgDomain.getSenderId());
        sendboxMsgs.setMsgId(grpMsgDomain.getMessageId());
        sendboxMsgs.setTargetId(grpMsgDomain.getCid());
        sendboxMsgs.setAppKey(grpMsgDomain.getAppKey());
        sendboxMsgs.setPayload(grpMsgDomain.getPayload());
        sendboxMsgs.setPayloadType(grpMsgDomain.getPayloadType());
        sendboxMsgs.setSendTime(grpMsgDomain.getSendTime());
        sendboxMsgs.setConverType(2); // c2g
        sendboxMsgsMapper.insert(sendboxMsgs);
        return Boolean.TRUE;
    }

}
